package cn.tedu.voice.system.speech;

import com.baidu.aip.speech.AipSpeech;
import org.json.JSONObject;

/**
 * 处理语音识别类
 *
 * @author java@ccl.cn
 * @version 0.0.1
 */
public class Sample {
    //设置APPID/AK/SK
    public static final String APP_ID = "31891224";
    public static final String API_KEY = "RsvMsLIovHxSrYstxk8zyPXs";
    public static final String SECRET_KEY = "fVUGPsx9qmlwsW1TT4cMwguNAcT2fbjt";

    public static void main(String[] args) {
      know("16k.pcm");
    }
    public static void know(String filename){        // 初始化一个AipSpeech
        AipSpeech client = new AipSpeech(APP_ID,API_KEY,SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        //直接通过jvm启动参数设置此环境变量
        System.setProperty("aip.log4j.conf", "log4j.properties");

        // 调用接口
        JSONObject res = client.asr(filename,filename.substring(filename.length()-3),16000,null);
        System.out.println(res.toString(2));
    }
}
